package openrouter

import (
	"fmt"
	"time"
)

type ClientConfig struct {
	authToken string

	BaseURL          string
	OrgID            string
	AssistantVersion string
	XTitle           string

	EmptyMessagesLimit uint
	Timeout            time.Duration
	Headers            map[string]string
}

type Option func(*ClientConfig)

const defaultEmptyMessagesLimit = 10

func DefaultConfig(apiKey string) *ClientConfig {
	return &ClientConfig{
		authToken:          apiKey,
		BaseURL:            "https://openrouter.ai/api/v1",
		XTitle:             "OpenRouter-Go-Client",
		EmptyMessagesLimit: defaultEmptyMessagesLimit,
		Timeout:            60 * time.Second,
		Headers: map[string]string{
			"HTTP-Referer":  "https://daived.com",
			"Authorization": fmt.Sprintf("Bearer %s", apiKey),
			"X-Title":       "OpenRouter-Go-Client",
		},
	}
}

func WithXTitle(title string) Option {
	return func(c *ClientConfig) {
		c.XTitle = title
		c.Headers["X-Title"] = title
	}
}

func WithTimeout(timeout time.Duration) Option {
	return func(c *ClientConfig) {
		c.Timeout = timeout
	}
}
